@extends('back_end.layouts.default_info')

{{-- Web site Title --}}
@section('title')
{{{ Lang::get('general.back_end.setting') }}} {{Lang::get('general.edit') }} :: @parent
@stop
@section('content_header')
{{{ Lang::get('general.back_end.setting') }}} {{Lang::get('general.edit') }}
@stop
{{-- breadcrumb --}}
@section('breadcrumb')
<li><a href="#"><i class="fa fa-dashboard"></i> {{{ Lang::get('general.back_end.home') }}}</a></li>
<li class="active">{{{ Lang::get('general.back_end.setting') }}} {{Lang::get('general.edit') }}</li>
@stop

{{-- Content --}}
@section('content')
<div class="box box-primary">

  {{-- Create Form --}}
    {{ Form::open(array('action' => array('BackSettingController@doUpdate',$entry->id))) }}
    <div class="box-body">
      <!-- Tabs -->
      <ul class="nav nav-tabs">
        <li class="active"><a href="#tab-general" data-toggle="tab">基本信息</a></li>
      </ul>
      <!-- ./ tabs -->


      <!-- Tabs Content -->
      <div class="tab-content">
        <!-- General tab -->
        <div class="tab-pane active" id="tab-general">
          <br/>
            {{ $tab_index = 1 ? '' : '' }}
            {{ $tab_index++ }}
            {{ Form::textGroup('site_url',  Setting::$column['site_url'],   Input::old('site_url', isset($entry) ? $entry->site_url : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('company_name', Setting::$column['company_name'], Input::old('company_name', isset($entry) ? $entry->company_name : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('master_email', Setting::$column['master_email'], Input::old('master_email', isset($entry) ? $entry->master_email : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('address', Setting::$column['address'], Input::old('address', isset($entry) ? $entry->address : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('service_phone', Setting::$column['service_phone'], Input::old('service_phone', isset($entry) ? $entry->service_phone : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('mobile', Setting::$column['mobile'], Input::old('mobile', isset($entry) ? $entry->mobile : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('app_url', Setting::$column['app_url'], Input::old('app_url', isset($entry) ? $entry->app_url : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('app_id', Setting::$column['app_id'], Input::old('app_id', isset($entry) ? $entry->app_id : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('app_secret', Setting::$column['app_secret'], Input::old('app_secret', isset($entry) ? $entry->app_secret : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('access_token', Setting::$column['access_token'], Input::old('access_token', isset($entry) ? $entry->access_token : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('access_token_expires_in', Setting::$column['access_token_expires_in'], Input::old('access_token_expires_in', isset($entry) ? $entry->access_token_expires_in : ''),   $errors, $tab_index++, true) }}

            {{ Form::textGroup('integral_scale', Setting::$column['integral_scale'], Input::old('integral_scale', isset($entry) ? $entry->integral_scale : ''),   $errors, $tab_index++, true) }}

            {{ Form::textAreaGroup('company_instroductions', Setting::$column['company_instroductions'], Input::old('company_instroductions', isset($entry) ? $entry->company_instroductions : ''),   $errors, $tab_index++, true, 12) }}
        </div>
        <!-- ./ general tab -->

      </div>
      <!-- ./ tabs content -->

      {{ Form::submitButtonGroup('BackSettingController@doUpdate', (Auth::user()->can('manage_setting')) , $tab_index) }}

      <!-- ./ form actions -->
    </div>
    {{ Form::close() }}
</div>
@stop


{{-- Scripts --}}
@section('scripts')
<script type="text/javascript">

    $(function () {
        var url = "{{{ URL::to('file/image') }}}"+"?_token={{{ csrf_token() }}}";

        $('.thumbnails button.destroy').click(addRemoveEventHandler);

        function addRemoveEventHandler(){
            var self = $(this);
            var file = self.attr('data-file');
            $.ajax({
                url: url + '&upload[0]=' + encodeURIComponent(file),
                type: 'DELETE'
            }).done(function( data ) {
                    var data = JSON.parse(data);
                    var file = self.attr('data-file');
                    if(data[file]){
                        self.parent('.thumbnails').siblings('input[id="thumbs['+file+']"]').remove();
                        self.parent('.thumbnails').remove();
                    }else{
                        var error = $('<div class="alert"/>').text("{{{ Lang::get('admin/general.delete_fail') }}}").append('<button type="button" class="close" data-dismiss="alert">&times;</button>');
                        $('.thumbnails-box').after(error);
                    }
                });
        }

        $('#imageupload').fileupload({
            url: url,
            dataType: 'json',
            done: function (e, data) {
                $.each(data.result.upload, function (index, file) {
                    if(file.error){
                        var error = $('<div class="alert"/>').text(file.error).append('<button type="button" class="close" data-dismiss="alert">&times;</button>');
                        $('.thumbnails-box').after(error);
                    }else{
                        $('.thumbnails-box').append(getNewThumb(file.name));
                        $('.thumbnails').show();
                        $('.progress').hide();
                        $('.thumbnails button.destroy[data-file="'+file.name+'"]').click(addRemoveEventHandler);
                    }
                });
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('.progress .bar').show();
                $('.progress .bar').css(
                    'width',
                    progress + '%'
                );
            }
        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');

        function getNewThumb(name){
            return '<div class="thumbnails">\
                <button type="button" class="btn btn-danger destroy" data-file="'+name+'">\
                <i class="icon-trash"></i>\
                <span>Delete</span>\
            </button>\
            <a href="#" class="thumbnail">\
                <img alt="" src="{{ URL::to('file/image?name=') }}'+name+'">\
                </a>\
            </div>\
            <input class="form-control" type="hidden" name="thumbs['+name+']" id="thumbs['+name+']" value="'+name+'" />';
        }


    });
</script>
@stop